class Index{
    int index;
}
class GfG {
    // Complete the function
    Node buildUtil(int in[],int post[],int st,int end,Index pIndex)
    {
        //return null;
        if(st>end)
        {
            return null;
        }
        Node n=new Node(post[pIndex.index]);
        (pIndex.index)--;
        
        if(st==end)
        {
            return n;
        }
        
        int x=search(in,st,end,n.data);
        
        n.right=buildUtil(in,post,x+1,end,pIndex);
        n.left=buildUtil(in,post,st,x-1,pIndex);
        
        return n;
    }
    
    int search(int in[],int st,int end,int key)
    {
        int i;
        for(i=st;i<=end;i++){
            if(in[i]==key){
                break;

            }
        }
        return i;
    }
    Node buildTree(int in[], int post[], int n) {
        // Your code here
        Index pIndex=new Index();
        pIndex.index=n-1;
        return buildUtil(in,post,0,n-1,pIndex);
    }
}
